package com.itgy.project.provider;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itgy.project.common.ErrorCode;
import com.itgy.project.exception.BusinessException;
import com.itgy.project.mapper.InterfaceInfoMapper;
import com.itgy.project.model.entity.InterfaceInfo;
import com.itgy.project.provider.InnerInterfaceInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

@DubboService
public class InnerInterfaceInfoImpl implements InnerInterfaceInfo {

    @Resource
    private InterfaceInfoMapper interfaceInfoMapper;

    @Override
    public String getInterfaceInfoId(String url, String method) {

        if(StringUtils.isAnyBlank(url,method))
        {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }

        LambdaQueryWrapper<InterfaceInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(InterfaceInfo::getUrl,url).eq(InterfaceInfo::getMethod,method);

        InterfaceInfo interfaceInfo = interfaceInfoMapper.selectOne(lambdaQueryWrapper);
        if(interfaceInfo==null)
            return null;

        return interfaceInfo.getId().toString();
    }
//    @Override
//    public InterfaceInfo getInterfaceInfo(String url, String method) {
//        if(StringUtils.isAnyBlank(url,method))
//        {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR);
//        }
//        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("url",url).eq("method",method);
//        InterfaceInfo interfaceInfo = interfaceInfoMapper.selectOne(queryWrapper);
//        return interfaceInfo;
//    }
}
